package com.hl.qzzpbackend.controller;
import com.hl.qzzpbackend.common.BaseResponse;
import com.hl.qzzpbackend.common.DeleteRequest;
import com.hl.qzzpbackend.common.ResultUtils;
import com.hl.qzzpbackend.model.dto.resume.ResumeRenameRequest;
import com.hl.qzzpbackend.model.entity.User;
import com.hl.qzzpbackend.model.vo.ResumeVO;
import com.hl.qzzpbackend.service.ResumeService;
import com.hl.qzzpbackend.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;


/**
 * 简历附件接口
 * @author helong
 */
@Slf4j
@Api(tags = "简历附件接口")
@RestController
@RequestMapping("/resume")
public class ResumeController {

    @Resource
    private ResumeService resumeService;

    @Resource
    private UserService userService;


    // 简历附件重命名
    @ApiOperation(value = "简历附件重命名")
    @RequestMapping(value = "/rename", method = RequestMethod.POST)
    public BaseResponse<Boolean> resumeRename(@Valid @RequestBody ResumeRenameRequest resumeRenameRequest, HttpServletRequest request) {
        if(log.isInfoEnabled()){
            log.info("简历附件重命名 {}", resumeRenameRequest);
        }
        User loginUser = userService.getLoginUser(request);
        boolean result = resumeService.resumeRename(resumeRenameRequest,loginUser);
        return ResultUtils.success(result);
    }


    // 获取简历列表
    @ApiOperation(value = "获取简历列表")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public BaseResponse<List<ResumeVO>> getResumeList(HttpServletRequest request) {
        if(log.isInfoEnabled()){
            log.info("获取简历列表");
        }
        User loginUser = userService.getLoginUser(request);
        List<ResumeVO> resumeVOList= resumeService.getResumeList(loginUser);
        return ResultUtils.success(resumeVOList);
    }

    // 删除简历
    @ApiOperation(value = "删除简历")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public BaseResponse<Boolean> deleteResume(@Valid @RequestBody DeleteRequest deleteRequest) {
        if(log.isInfoEnabled()){
            log.info("删除简历 {}",deleteRequest);
        }
        boolean result = resumeService.deleteResume(deleteRequest);
        return ResultUtils.success(result);
    }


}
